import './App.css'
import React from 'react'
import LoginPage from './components/pages/login/LoginPage'
import { Redirect, Route, Switch as SwitchRouter } from 'react-router-dom'
import HomePage from './components/pages/home/HomePage'
import RegisterPage from './components/pages/register/RegisterPage'
import AdminPage from './components/pages/admin/AdminPage'
import { connect } from 'react-redux'
import { admin_load_access_token, loadUserState } from './_redux/actions'
import { Button, Result } from 'antd'
import CenterLayout from './components/CenterLayout'

class App extends React.Component {
  componentWillMount () {
    this.props.loadUserState()
    this.props.admin_load_access_token()
  }

  render () {
    return (
      <SwitchRouter>
        <Route path="/home"><HomePage/></Route>
        <Route path="/login"><LoginPage/></Route>
        <Route path="/register"><RegisterPage/></Route>
        <Route path="/admin"><AdminPage/></Route>
        <Route path="/reg-success">
          <CenterLayout>
            <Result title="注册成功" extra={<Button href="/login" type="primary">现在登录</Button>}/>
          </CenterLayout>
        </Route>
        <Route path="/">
          <Redirect to="/home"/>
        </Route>
      </SwitchRouter>
    )
  }
}

App = connect(
  () => ({}),
  { loadUserState, admin_load_access_token }
)(App)

export default App
